<template>
  <div class="listContentBox">
    <advancedQueryShrinkComponent ref="advancedQueryShrinkComponent" :labelLength="5" :queryData="queryData" @getQuery="getList" />
    <div class="listBox p-rem-l-24   p-rem-r-24 p-rem-t-16 p-rem-b-16">
      <el-row class="listBoxbtn m-rem-b-16">
        <el-col :span="4">
          <el-button type="primary" add @click="handleJump('add','')">新增</el-button>
        </el-col>
      </el-row>
      <div class="listBoxTable">
        <el-table v-loading="listLoading" stripe :data="list" height="100%">
          <el-table-column label="序号" type="index" width="80" align="center" fixed="left">
            <template slot-scope="scope">
              <span>{{ pageIndex(scope.$index, queryData.queryParams) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="新闻标题" prop="title" show-overflow-tooltip min-width="300px" />
          <el-table-column label="栏目" prop="newsTypeName" show-overflow-tooltip width="100"/>
<!--          <el-table-column label="文号" prop="documentNumber" show-overflow-tooltip min-width="150px"/>-->
          <el-table-column label="信息来源" prop="source" show-overflow-tooltip min-width="200px"/>
          <el-table-column label="访问量" prop="readNumber" width="80" />
          <el-table-column label="发布日期" prop="releaseTime" show-overflow-tooltip width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.releaseTime ,'{y}-{m}-{d}  {h}:{i}') }}</span>
            </template>
          </el-table-column>
<!--          <el-table-column label="置顶" width="100" prop="top">-->
<!--            <template slot-scope="scope">-->
<!--              <el-switch-->
<!--                v-model="scope.row.isTop"-->
<!--                active-value="Y"-->
<!--                inactive-value="N"-->
<!--                @change="handleSwitchChange(scope.row,'置顶')"-->
<!--              >-->
<!--              </el-switch>-->
<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column label="新闻状态" prop="releaseStatusLabel" width="100" />
          <el-table-column label="操作" align="center" fixed="right" width="200">
            <template slot-scope="scope">
              <el-button v-show="userId == scope.row.createBy && scope.row.releaseStatus !=='01'" type="text" @click="handleJump('edit',scope.row)">修改</el-button>
              <el-button v-show="userId == scope.row.createBy && scope.row.releaseStatus !=='01'" type="text" @click="handleConfirm({id:scope.row.id,releaseStatus:'01'}, '/news-info/releaseById', '发布')">发布</el-button>
              <el-button v-show="userId == scope.row.createBy && scope.row.releaseStatus ==='01'" type="text" @click="handleConfirm({id:scope.row.id,releaseStatus:'02'}, '/news-info/offlineById', '下线')">下线</el-button>
              <el-button v-show="userId == scope.row.createBy && scope.row.releaseStatus !=='01'" type="text" typeC="danger" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
          <!-- 列表缺省 -->
          <div slot="empty" class="zjm_no_data_table_list height-100 flex row-center col-center">
            <el-empty :image-size="70" description="暂无数据"></el-empty>
          </div>
        </el-table>
      </div>
      <pagination :total="listTotal" :page.sync="queryData.queryParams.pageNum" :limit.sync="queryData.queryParams.pageSize" @pagination="getList" />
    </div>
  </div>

</template>

<script>
// 混入
import { listMixins } from '@/mixins/publicMixins/listMixins'
// 组件
import advancedQueryShrinkComponent from '@/components/publicComponents/advancedQuery/indexShrink.vue'
// ------------------------------------------------------------------------
export default {
  name: 'List',
  mixins: [listMixins],
  components: { advancedQueryShrinkComponent },
  provide() {
    return {
      listQueryParams: this
    }
  },
  data() {
    return {
      // 查询条件+查询组
      queryData: {
        queryParams: {
          pageNum: 1, // 分页的初始值
          pageSize: 10 // 每页的显示数
        },
        data: [
          {
            label: '新闻标题', // 前端展示的label
            type: 'input', // 格式：input/select/date/money/number
            value: null, // 查询回填值
            valueKey: 'title' // 查询入参Key
          },
          {
            label: '新闻状态', // 前端展示的label
            type: 'select', // 格式：select
            value: null, // 查询回填值
            valueKey: 'releaseStatus', // 查询入参Key
            typeData: [], // select类储存options
            dataType: 'dicts', // 获取储存options的类型  数据字典：dicts，其他接口获取：url
            getDicts: 'news_release_status', // 数据字典类型值
            multiple: false// 是不是多选
          },
          {
            label: '栏目', // 前端展示的label
            type: 'select', // 格式：select
            value: null, // 查询回填值
            valueKey: 'newsType', // 查询入参Key
            typeData: [], // select类储存options
            dataType: 'url', // 获取储存options的类型  数据字典：dicts，其他接口获取：url
            getUrl: '/ent-news-type/getAll', // // 如果不是数据字典，把后台服务路径传入
            getUrlListBool: false, // 接口返回格式时候为常规数则  例如:[2020,2021]
            getUrlData: null, // 入参
            getUrlMethod: 'get', // 请求类型
            getUrlDictValue: 'id', // 回填时Value的key
            getUrlDictLabel: 'name', //  回填时Label的key
            multiple: false// 是不是多选
          }
        ]
      }
    }
  },
  created() {},

  mounted() {},
  methods: {
    /**
     * @description: 列表
     * @Author: baoxuhui
     * @param {*} queryParams
     * @return {*}
     */
    getList(queryParams) {
      this.getListMixins('/ent-news/getPage', queryParams)
    },

    /**
     * @description: 状态修改
     * @Author: baoxuhui
     * @param {*} row
     * @param {*} text
     * @return {*}
     */
    // handleSwitchChange(row, text) {
    //   const data = {
    //     id: row.id,
    //     isTop: row.isTop
    //   }
    //   this.handleSwitchChangeMixins('/ent-news/topById', data, text)
    // },

    /**
     * @description: 跳转
     * @Author: baoxuhui
     * @param {*} type
     * @param {*} row
     * @param {*} url
     * @return {*}
     */
    handleJump(type, row, url = '') {
      const queryParams = {}
      if (row) {
        queryParams.id = row.id
      }
      this.handleJumpMixins(type, queryParams, url)
    },

    /**
     * @Description: 弹窗确定后调取相应接口
     * @author zhangjiamin
     * @param {*} row  当前值
     * @param {*} apiUrl api路径
     * @param {*} text 确认要 text 吗?
     * @return {*}
     */
    handleConfirm(row, apiUrl, text) {
      const data = { id: row.id, }
      this.handleConfirmMixins(apiUrl, data, text)
    },

    /**
     * @description: 删除
     * @Author: baoxuhui
     * @param {*} row
     * @return {*}
     */
    handleDelete(row) {
      console.log(row)
      const data = {
        id: row.id
      }
      const url = '/ent-news/removeById'
      this.handleDeleteMixins(url, data)
    }
  }
}
</script>

